package com.jxwifi.cloud.quickclean.orderdetails;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.CountDownTimer;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.idroid.utils.NoDoubleClickListener;
import com.idroid.utils.TextDrawable;
import com.idroid.widget.LoadDialog;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.app.StateUtils;
import com.jxwifi.cloud.quickclean.app.UrlPool;
import com.jxwifi.cloud.quickclean.bean.CardRollBean;
import com.jxwifi.cloud.quickclean.bean.DiscountsBean;
import com.jxwifi.cloud.quickclean.bean.OrderDetailsBean;
import com.jxwifi.cloud.quickclean.bean.PayParamsBean;
import com.jxwifi.cloud.quickclean.bean.PriceDetailBean;
import com.jxwifi.cloud.quickclean.bean.RewardBean;
import com.jxwifi.cloud.quickclean.bean.SystemBean;
import com.jxwifi.cloud.quickclean.bean.UcCustomerBank;
import com.jxwifi.cloud.quickclean.cleanermap.CleaningMapActivity;
import com.jxwifi.cloud.quickclean.complaint.ComplaintActivity;
import com.jxwifi.cloud.quickclean.main.PriceExplainActivity;
import com.jxwifi.cloud.quickclean.model.AuzImpl;
import com.jxwifi.cloud.quickclean.okhttp.Params;
import com.jxwifi.cloud.quickclean.order.ProductDetailsActivity;
import com.jxwifi.cloud.quickclean.pay.PayResult;
import com.jxwifi.cloud.quickclean.pay.PayUtil;
import com.jxwifi.cloud.quickclean.popwindow.PopEvaluateModule;
import com.jxwifi.cloud.quickclean.popwindow.PopOrderStartModule;
import com.jxwifi.cloud.quickclean.popwindow.PopPayDepositModule;
import com.jxwifi.cloud.quickclean.popwindow.PopPayModule;
import com.jxwifi.cloud.quickclean.popwindow.PopPayOrderModule;
import com.jxwifi.cloud.quickclean.popwindow.PopRewardModule;
import com.jxwifi.cloud.quickclean.popwindow.PopRightModule;
import com.jxwifi.cloud.quickclean.popwindow.PopTimeChoiceModule;
import com.jxwifi.cloud.quickclean.utils.CancelReasonDialog;
import com.jxwifi.cloud.quickclean.utils.KAlertDialog;
import com.jxwifi.cloud.quickclean.utils.ToastUtils;
import com.jxwifi.cloud.quickclean.utils.ToastUtilsKing;
import com.jxwifi.cloud.quickclean.utils.TokenTimeUtils;
import com.popwindow.PopWindowUtil;
import com.popwindow.Popwindows;
import com.view.SuperSwipeRefreshLayout;

import org.simple.eventbus.EventBus;

import java.math.BigDecimal;
import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import cn.trinea.android.common.util.ListUtils;

public class OrderDetailsPresenter {

    private String TAG = this.getClass().getSimpleName();
    private Context mContext;
    private OrderDetailsView mView;
    private AuzImpl mAuz;

    private String mCustomer;
    public OrderDetailsBean mOrderDetails;

    private ProgressBar progressBar;
    private TextView textView;
    private ImageView imageView;

    private boolean mIsFinished = true;
    private boolean mIsLocation = true;//保洁员位置查看条件
    private boolean mIsPhone = true;//保洁员电话拨打条件

    private String mCouponCustomerCode = "";//优惠卷编码
    private double mCouponsdiscount = 0.00;
    private PopPayOrderModule mPopPayOrder;


    private double mTotalAmount;//快洁宝用户余额
    private String mStart;//余额状态
    private CountDownTimer mTimer;
    private int mStartsTime = 8; //开始时间
    private int mTimeInterval = 1;//时间间隔
    private int mEndTime = 18;//结束时间

    private Popwindows window;
    public LoadDialog mLoadDialog;//加载动画
    private KAlertDialog dialogshoweminder;
    private double discount;//折扣优惠
    private double minus;//立减优惠

    public OrderDetailsPresenter(Context context, OrderDetailsView view) {
        this.mContext = context;
        this.mView = view;
        this.mAuz = new AuzImpl();
    }

    //右上角点击显示
    public void DialogShow() {
        if ("".equals(mOrderDetails) || "null".equals(mOrderDetails.getOrderInfo())) {
            return;
        }
        PopRightModule mModule = new PopRightModule(mContext, mOrderDetails.getOrderInfo().getOrderStatus(), mOrderDetails.getComment(), new PopRightModule.PopRightListener() {
            /*@Override
            public void Retransmission() { //重发
                getRetransmission();
            }*/

            @Override
            public void Evaluate() { //评价
                final KAlertDialog dialogshow=new KAlertDialog(mContext,"是否评价！");
                dialogshow.setRightTxt("确定", new NoDoubleClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {
                        getEvaluate();
                        dialogshow.dismiss();
                    }
                });
                dialogshow.show();
            }

            @Override
            public void Cancel() { //取消
                cancelReasonDialog();
            }

            @Override
            public void Complaint() { //投诉
                final KAlertDialog dialogshow=new KAlertDialog(mContext,"是否投诉此订单！");
                dialogshow.setRightTxt("确定", new NoDoubleClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {
                        Intent intent = new Intent();
                        intent.setClass(mContext, ComplaintActivity.class);
                        intent.putExtra("orderinfo", mOrderDetails.getOrderInfo());
                        mContext.startActivity(intent);
                        dialogshow.dismiss();
                    }
                });
                dialogshow.show();
            }

            @Override
            public void CustomerService() { //联系客服
                inittell();
            }
        });
        Popwindows window = PopWindowUtil.getPopupWindow(mModule.getView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
                .LayoutParams.MATCH_PARENT);
        mModule.setPopwindow(window);
        window.show(mView.getRelImgDian(), Popwindows.Location.TOP);
    }

    //订单详情接口
    public void getData() {
        Params params = new Params();
        params.add("orderCode", mView.getOrderCode());
        mAuz.auzget(UrlPool.GET_ORDER_INFO, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                //Log.i(TAG,"getData ==> AuzSuccess");
                if (code == 0) {
                    mOrderDetails = JSON.parseObject(data, OrderDetailsBean.class);
                    if (mOrderDetails.getUcCustomerBank() != null) {
                        mTotalAmount = Double.valueOf(mOrderDetails.getUcCustomerBank().getSurplusAmount());
                        mStart=mOrderDetails.getUcCustomerBank().getStatus();
                    } else {
                        mTotalAmount = 0.0;
                        mStart=StateUtils.NORMAL;
                    }
                    initView();
                } else {
                    mView.onData();
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                Log.i(TAG,"getData ==> AuzFailure");
                mView.onFailure(errorCode, msg);
            }
        });
    }


    public void deafaultView(){
        mView.getCleaning().setVisibility(View.GONE);
        mView.getWorkBenchTime().setVisibility(View.GONE);
        mView.getPayment().setVisibility(View.GONE);
        mView.getDetailsCenter().setVisibility(View.VISIBLE);
        mView.getDetailsStarts().setVisibility(View.VISIBLE);
        mView.getCleaningReward().setVisibility(View.GONE);
        mView.getCollection().setVisibility(View.GONE);
        mView.getChangeTime().setVisibility(View.VISIBLE);
        //OrderStartsTitle();
        //mView.getServiceTime(mOrderDetails.getOrderInfo().getServiceTime());
        //OrderCenter();
        mView.getExplainReturn().setVisibility(View.GONE);
        mView.getExplain().setVisibility(View.VISIBLE);
        mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
        mView.onShowToster();
        mIsFinished = true;
    }

    public void initView() {
        StartsType(mOrderDetails.getOrderInfo().getOrderStatus());
        if (StateUtils.DP_ING.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //派单中
            mView.getCleaning().setVisibility(View.GONE);
            mView.getWorkBenchTime().setVisibility(View.GONE);
            mView.getPayment().setVisibility(View.GONE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getCleaningReward().setVisibility(View.GONE);
            mView.getCollection().setVisibility(View.GONE);
            mView.getChangeTime().setVisibility(View.VISIBLE);
            OrderStartsTitle();
            mView.getServiceTime(mOrderDetails.getOrderInfo().getServiceTime());
            OrderCenter();
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
            mView.onShowToster();
            mIsFinished = true;

        } else if (StateUtils.SER_START.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已派单
            mView.getCleaning().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getWorkBenchTime().setVisibility(View.GONE);
            mView.getPayment().setVisibility(View.GONE);
            mView.getCleaningReward().setVisibility(View.GONE);
            mView.getCollection().setVisibility(View.GONE);
            mView.getChangeTime().setVisibility(View.VISIBLE);
            Cleaningbuju();
            OrderStartsTitle();
            OrderCenter();
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
            TextDrawable.drawable(mContext, mView.getCleaningLocation(), R.mipmap.icon_order_details_cleaning, 1);
            TextDrawable.drawable(mContext, mView.getCleaningPhone(), R.mipmap.icon_cleaning_phone, 1);
            mIsPhone = true;
            mIsLocation = true;
            mIsFinished = true;

        } else if (StateUtils.SER_LEAVE.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已出发
            mView.getCleaning().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getWorkBenchTime().setVisibility(View.GONE);
            mView.getPayment().setVisibility(View.GONE);
            mView.getCleaningReward().setVisibility(View.GONE);
            mView.getCollection().setVisibility(View.GONE);
            mView.getChangeTime().setVisibility(View.GONE);
            Cleaningbuju();
            OrderStartsTitle();
            OrderCenter();
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
            TextDrawable.drawable(mContext, mView.getCleaningLocation(), R.mipmap.icon_order_details_cleaning, 1);
            TextDrawable.drawable(mContext, mView.getCleaningPhone(), R.mipmap.icon_cleaning_phone, 1);
            mIsPhone = true;
            mIsLocation = true;
            mIsFinished = true;

        } else if (StateUtils.SER_ARRIVE.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已到达
            mView.getCleaning().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getWorkBenchTime().setVisibility(View.GONE);
            mView.getPayment().setVisibility(View.GONE);
            mView.getCleaningReward().setVisibility(View.GONE);
            mView.getCollection().setVisibility(View.GONE);
            mView.getChangeTime().setVisibility(View.GONE);
            Cleaningbuju();
            OrderStartsTitle();
            OrderCenter();
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
            TextDrawable.drawable(mContext, mView.getCleaningLocation(), R.mipmap.icon_order_details_cleaning, 1);
            TextDrawable.drawable(mContext, mView.getCleaningPhone(), R.mipmap.icon_cleaning_phone, 1);
            mIsPhone = true;
            mIsLocation = true;
            mIsFinished = true;

        } else if (StateUtils.SER_TIME_START.equals(mOrderDetails.getOrderInfo().getOrderStatus()) || StateUtils.SER_TIME_STOP.equals(mOrderDetails.getOrderInfo().getOrderStatus())
                || StateUtils.SER_TIME_START_RE.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已开始 已暂停 计时重新开始
            mView.getCleaning().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getWorkBenchTime().setVisibility(View.VISIBLE);
            mView.getPayment().setVisibility(View.GONE);
            mView.getCleaningReward().setVisibility(View.GONE);
            mView.getCollection().setVisibility(View.GONE);
            mView.getChangeTime().setVisibility(View.GONE);
            Cleaningbuju();
            OrderStartsTitle();
            OrderCenter();
            initgettime();
            if (StateUtils.SER_TIME_START.equals(mOrderDetails.getOrderInfo().getOrderStatus()) || StateUtils.SER_TIME_START_RE.equals(mOrderDetails.getOrderInfo().getOrderStatus())) {
                setTimerCount();//计时操作每60秒执行一次
            }
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
            TextDrawable.drawable(mContext, mView.getCleaningLocation(), R.mipmap.icon_order_details_cleaning, 1);
            TextDrawable.drawable(mContext, mView.getCleaningPhone(), R.mipmap.icon_cleaning_phone, 1);
            mIsPhone = true;
            mIsLocation = true;
            mIsFinished = true;

        } else if (StateUtils.CANCEL.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已取消
            mView.getCleaning().setVisibility(View.GONE);
            mView.getWorkBenchTime().setVisibility(View.GONE);
            mView.getPayment().setVisibility(View.GONE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getCleaningReward().setVisibility(View.GONE);
            mView.getCollection().setVisibility(View.GONE);
            mView.getChangeTime().setVisibility(View.GONE);
            OrderStartsTitle();
            OrderCenter();
            onTimeCancel();
            mView.getExplainReturn().setVisibility(View.VISIBLE);
            mView.getExplain().setVisibility(View.GONE);
            mView.getTitlebarText().setText(StateUtils.ORDER_CANCEL);

        } else if (StateUtils.OUT_TIME_CANCEL.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已过期
            mView.getCleaning().setVisibility(View.GONE);
            mView.getWorkBenchTime().setVisibility(View.GONE);
            mView.getPayment().setVisibility(View.GONE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getCleaningReward().setVisibility(View.GONE);
            mView.getCollection().setVisibility(View.GONE);
            mView.getChangeTime().setVisibility(View.GONE);
            OrderStartsTitle();
            OrderCenter();
            onTimeCancel();
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getTitlebarText().setText(StateUtils.ORDER_OVERDUE);

        } else if (StateUtils.SER_FINISHED.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已完成(待支付)
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getCleaning().setVisibility(View.VISIBLE);
            mView.getWorkBenchTime().setVisibility(View.VISIBLE);
            mView.getPayment().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getCleaningReward().setVisibility(View.VISIBLE);
            mView.getCollection().setVisibility(View.VISIBLE);
            if(mOrderDetails.getCleanerInfo().isCollected()){
                TextDrawable.drawable(mContext, mView.getCollection(), R.drawable.collection_selector, 1);
            }else {
                TextDrawable.drawable(mContext, mView.getCollection(), R.drawable.uncollection_selector, 1);
            }
            mView.getChangeTime().setVisibility(View.GONE);
            OrderStartsTitle();
            Cleaningbuju();
            initgettime();
            OrderCenter();
            onTimeCancel();
            getCoupons();
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
            TextDrawable.drawable(mContext, mView.getCleaningLocation(), R.mipmap.icon_order_details_cleaning_un, 1);
            TextDrawable.drawable(mContext, mView.getCleaningPhone(), R.mipmap.icon_cleaning_phone_un, 1);
            mView.getCleaningLocation().setVisibility(View.GONE);
            mView.getCleaningPhone().setVisibility(View.GONE);
            mIsPhone = false;
            mIsLocation = false;
            mIsFinished = false;

        } else if (StateUtils.SER_END.equals(mOrderDetails.getOrderInfo().getOrderStatus())) { //已完成(已支付)
            mView.getPayment().setVisibility(View.GONE);
            mView.getDetailsCenter().setVisibility(View.VISIBLE);
            mView.getCleaning().setVisibility(View.VISIBLE);
            mView.getWorkBenchTime().setVisibility(View.VISIBLE);
            mView.getDetailsStarts().setVisibility(View.VISIBLE);
            mView.getCleaningReward().setVisibility(View.VISIBLE);
            mView.getCollection().setVisibility(View.VISIBLE);
            if(mOrderDetails.getCleanerInfo().isCollected()){
                TextDrawable.drawable(mContext, mView.getCollection(), R.drawable.collection_selector, 1);
            }else {
                TextDrawable.drawable(mContext, mView.getCollection(), R.drawable.uncollection_selector, 1);
            }
            mView.getChangeTime().setVisibility(View.GONE);
            OrderStartsTitle();
            Cleaningbuju();
            initgettime();
            OrderCenter();
            onTimeCancel();
            if (mOrderDetails.getComment() == null) {
                getEvaluate();
            }
            mView.getExplain().setVisibility(View.VISIBLE);
            mView.getExplainReturn().setVisibility(View.GONE);
            mView.getTitlebarText().setText(StateUtils.ORDER_DETAILS);
            TextDrawable.drawable(mContext, mView.getCleaningLocation(), R.mipmap.icon_order_details_cleaning_un, 1);
            TextDrawable.drawable(mContext, mView.getCleaningPhone(), R.mipmap.icon_cleaning_phone_un, 1);
            mView.getCleaningLocation().setVisibility(View.GONE);
            mView.getCleaningPhone().setVisibility(View.GONE);
            mIsPhone = false;
            mIsLocation = false;
            mIsFinished = false;
        }
        mView.getSvOrderDetails().setVisibility(View.VISIBLE);
        mView.onIsFinished(mIsFinished);
        mView.getSwip().setHeaderView(createHeaderView());
        mView.getSwip().setOnPullRefreshListener(new SuperSwipeRefreshLayout.OnPullRefreshListener() {

            @Override
            public void onRefresh() {
                textView.setText("正在刷新");
                imageView.setVisibility(View.GONE);
                progressBar.setVisibility(View.VISIBLE);
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        mView.getSwip().setRefreshing(false);
                        progressBar.setVisibility(View.GONE);
                        getData();
                    }
                }, 1000);
            }

            @Override
            public void onPullDistance(int distance) {
                // pull distance
            }

            @Override
            public void onPullEnable(boolean enable) {
                textView.setText(enable ? "松开刷新" : "下拉刷新");
                imageView.setVisibility(View.VISIBLE);
                imageView.setRotation(enable ? 180 : 0);
            }
        });
    }

    private View createHeaderView() {
        View headerView = LayoutInflater.from(mView.getSwip().getContext())
                .inflate(R.layout.layout_head, null);
        progressBar = (ProgressBar) headerView.findViewById(R.id.pb_view);
        textView = (TextView) headerView.findViewById(R.id.text_view);
        textView.setText("下拉刷新");
        imageView = (ImageView) headerView.findViewById(R.id.image_view);
        imageView.setVisibility(View.VISIBLE);
        imageView.setImageResource(R.drawable.down_arrow);
        progressBar.setVisibility(View.GONE);
        return headerView;
    }

    //保洁员显示数据
    public void Cleaningbuju() {
        if (null == mOrderDetails.getCleanerInfo() || "null".equals(mOrderDetails.getCleanerInfo())) {//判断有无保洁员信息为空不显示
            mView.getCleaning().setVisibility(View.GONE);
        } else {
            mView.getCleaning().setVisibility(View.VISIBLE);
            Glide.with(mContext).load(mOrderDetails.getCleanerInfo().getHeadImg()).dontAnimate().into(mView.getCircle());
            mView.getCleaningName().setText(mOrderDetails.getCleanerInfo().getRealName());
            mView.getRatingBar().setRating((float) (mOrderDetails.getCleanerInfo().getGrade() / 20));
        }
    }

    //保洁员位置
    public void CleamingLocation() {
        if (mIsLocation) { //判断是否可点击，在某些状态下是不可点击的
            Intent intent = new Intent();
            intent.setClass(mContext, CleaningMapActivity.class);
            intent.putExtra("order_details", mOrderDetails);
            mContext.startActivity(intent);
        }
    }

    //订单状态描述
    public void OrderStartsTitle() {
        if (mOrderDetails.getOptRecords().size() > 0) {
            mView.getDetailsProcess().setText(mOrderDetails.getOptRecords().get(0).getContent());
            mView.getStartsTime().setText(mOrderDetails.getOptRecords().get(0).getCreateTime());
        }
    }

    //派单状态描述
    public void StartsType(String starts) {
        //mTvInTheDispatch
        if (StateUtils.DP_ING.equals(starts)) { //派单中
            mView.getInTheDispatch().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            mView.getPaymentOfBills().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getHavingSetOut().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getDetailsArrived().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getBeginning().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getCompleted().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            //图标
            mView.getImgInTheDispatch().setBackgroundResource(R.mipmap.icon_order_details_distribute);
            mView.getImgPaymentOfBills().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgHavingSetOut().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgDetailsArrived().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgBeginning().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgCompleted().setBackgroundResource(R.mipmap.icon_order_details_start);

        } else if (StateUtils.SER_START.equals(starts)) { //已派单
            mView.getInTheDispatch().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getPaymentOfBills().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            mView.getHavingSetOut().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getDetailsArrived().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getBeginning().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getCompleted().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            //图标
            mView.getImgInTheDispatch().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgPaymentOfBills().setBackgroundResource(R.mipmap.icon_payment_of_bills);
            mView.getImgHavingSetOut().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgDetailsArrived().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgBeginning().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgCompleted().setBackgroundResource(R.mipmap.icon_order_details_start);
        } else if (StateUtils.SER_LEAVE.equals(starts)) { //已出发
            mView.getInTheDispatch().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getPaymentOfBills().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getHavingSetOut().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            mView.getDetailsArrived().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getBeginning().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getCompleted().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            //图标
            mView.getImgInTheDispatch().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgPaymentOfBills().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgHavingSetOut().setBackgroundResource(R.mipmap.icon_arrived);
            mView.getImgDetailsArrived().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgBeginning().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgCompleted().setBackgroundResource(R.mipmap.icon_order_details_start);
        } else if (StateUtils.SER_ARRIVE.equals(starts)) { //已到达
            mView.getInTheDispatch().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getPaymentOfBills().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getHavingSetOut().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getDetailsArrived().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            mView.getBeginning().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getCompleted().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            //图标
            mView.getImgInTheDispatch().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgPaymentOfBills().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgHavingSetOut().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgDetailsArrived().setBackgroundResource(R.mipmap.icon_locations);
            mView.getImgBeginning().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgCompleted().setBackgroundResource(R.mipmap.icon_order_details_start);
        } else if (StateUtils.SER_TIME_START.equals(starts) || StateUtils.SER_TIME_STOP.equals(starts)
                || StateUtils.SER_TIME_START_RE.equals(starts)) { //已开始 已暂停 计时重新开始
            mView.getInTheDispatch().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getPaymentOfBills().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getHavingSetOut().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getDetailsArrived().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getBeginning().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            mView.getCompleted().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            //图标
            mView.getImgInTheDispatch().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgPaymentOfBills().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgHavingSetOut().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgDetailsArrived().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgBeginning().setBackgroundResource(R.mipmap.icon_beginning);
            mView.getImgCompleted().setBackgroundResource(R.mipmap.icon_order_details_start);
        } else if (StateUtils.CANCEL.equals(starts) || StateUtils.OUT_TIME_CANCEL.equals(starts)) { //已取消 已过期
            mView.getInTheDispatch().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getPaymentOfBills().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getHavingSetOut().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getDetailsArrived().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getBeginning().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getCompleted().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            //图标
            mView.getImgInTheDispatch().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgPaymentOfBills().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgHavingSetOut().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgDetailsArrived().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgBeginning().setBackgroundResource(R.mipmap.icon_order_details_start);
            mView.getImgCompleted().setBackgroundResource(R.mipmap.icon_order_details_start);
        } else if (StateUtils.SER_FINISHED.equals(starts) || StateUtils.SER_END.equals(starts)) { //已完成(待支付) 已完成(已支付)
            mView.getInTheDispatch().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getPaymentOfBills().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getHavingSetOut().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getDetailsArrived().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getBeginning().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            mView.getCompleted().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            //图标
            mView.getImgInTheDispatch().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgPaymentOfBills().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgHavingSetOut().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgDetailsArrived().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgBeginning().setBackgroundResource(R.mipmap.icon_order_strtas);
            mView.getImgCompleted().setBackgroundResource(R.mipmap.icon_completed);
        }
    }

    //订单详情数据显示布局
    public void OrderCenter() {
        mView.getDetailsDeposit().setText(mOrderDetails.getOrderInfo().getDeposit() + "元");
        mView.getDetailsCleaner().setText(mOrderDetails.getOrderInfo().getProductName());
        mView.getServiceTimes().setText(mOrderDetails.getOrderInfo().getServiceTime());
        mView.getAddressContent().setText(mOrderDetails.getOrderInfo().getProvince() + "" + mOrderDetails.getOrderInfo().getCity() + "" + mOrderDetails.getOrderInfo().getArea() + "" + mOrderDetails.getOrderInfo().getAddress());
        mView.getDetailsPhone().setText(mOrderDetails.getOrderInfo().getUserTell());
        mView.getDetailsNumber().setText(mOrderDetails.getOrderInfo().getOrderCode());
        mView.getDetailsSize().setText(mOrderDetails.getOrderInfo().getAreaSize());

    }

    //保洁员拨打电话
    public void CleaningTell() {
        if (mIsPhone) {
            Params params = new Params();
            params.add("orderCode", mView.getOrderCode());
            mAuz.auzget(UrlPool.GET_GENERATE_CATM, params, new AuzImpl.AuzListener() {
                @Override
                public void AuzSuccess(int code, final String data) {
                    if (code == 0) {
                        if (!TextUtils.isEmpty(data)) {
                            final KAlertDialog dialogshow = new KAlertDialog(mContext, "确认当前手机号码是否和您的下单号码" + mOrderDetails.getOrderInfo().getUserTell() + "一致");
                            dialogshow.setRightTxt("确定", new NoDoubleClickListener() {
                                @Override
                                protected void onNoDoubleClick(View v) {
                                    Intent mTelintent = new Intent(Intent.ACTION_DIAL);
                                    Uri Urldata = Uri.parse("tel:" + data.replace("\\", ""));
                                    mTelintent.setData(Urldata);
                                    mContext.startActivity(mTelintent);
                                    dialogshow.dismiss();
                                }
                            });
                            dialogshow.show();
                        } else {
                            Toast toast = Toast.makeText(mContext, "保洁员电话与当前下单号相同，无法拨打", Toast.LENGTH_SHORT);
                            ToastUtils.showMyToast(toast, 3000);
                        }
                    }
                }

                @Override
                public void AuzFailure(int errorCode, String msg) {
                    mView.onFailure(errorCode, msg);
                }
            });

        }
    }

    //服务详情
    public void ServiceDetails() {
        Intent intent = new Intent();
        intent.setClass(mContext, ProductDetailsActivity.class);
        intent.putExtra("product_code", mOrderDetails.getOrderInfo().getProductCode());
        intent.putExtra("product_price_code", mOrderDetails.getOrderInfo().getProductPriceCode());
        mContext.startActivity(intent);
    }

    //倒计时操作
    private void setTimerCount() {
        mTimer = new CountDownTimer(60 * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                //Log.w("oushuhua", "计时操作(" + millisUntilFinished / 1000 + "s)");
            }

            @Override
            public void onFinish() {
                initgettime();
                setTimerCount();
            }
        };
        mTimer.start();
    }

    public void onTimeCancel() {
        if (mTimer != null) {
            mTimer.cancel();
        }
    }

    //获取保洁员服务总时长和金额
    public void initgettime() {
        Params params = new Params();
        params.add("orderCode", mView.getOrderCode());
        mAuz.auzpost(UrlPool.POST_CLEANER_OPT_GETTIME, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    JSONObject obj = JSON.parseObject(data);
                    String money = obj.getString("money");
                    long mtimes = obj.getLong("times");
                    String mServiceTime = TokenTimeUtils.change((int) mtimes);
                    String[] hoursmin = mServiceTime.split(":");
                    mView.getTimeHours().setText(hoursmin[0]);
                    mView.getTimeMines().setText(hoursmin[1]);
                    if (Double.valueOf(money) > Double.valueOf(mOrderDetails.getOrderInfo().getDeposit())) {
                        mView.getIncomeText().setText("" + money);
                    } else {
                        mView.getIncomeText().setText("" + mOrderDetails.getOrderInfo().getDeposit());
                    }
                } else {
                    mView.oninitgettime();
                }

            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //费用说明接口
    public void priceDetail() {
        Params params = new Params();
        params.add("productPriceCode", mOrderDetails.getOrderInfo().getProductPriceCode());
        params.add("tagCode", mOrderDetails.getOrderInfo().getTabCode());
        mAuz.auzpost(UrlPool.POST_PRICE_DETAIL, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    PriceDetailBean mBean = JSON.parseObject(data, PriceDetailBean.class);
                    Intent intent = new Intent();
                    intent.setClass(mContext, PriceExplainActivity.class);
                    intent.putExtra("defaultprice", mBean.getPredictPrice());
                    intent.putExtra("hours", mBean.getHource());
                    intent.putExtra("estimatemoney", mBean.getDeposit());
                    intent.putExtra("costdescription", mBean.getAreaSize());
                    mContext.startActivity(intent);
                } else {
                    mView.onpriceDetail();
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                Log.i(TAG,"priceDetail ==> AuzFailure");
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //取消订单
    public void getOrderCancle(final String cancelReason) {
        Params params = new Params();
        params.add("orderCode", mView.getOrderCode());
        params.add("cancelReason",cancelReason);
        mAuz.auzpost(UrlPool.POST_ORDER_CANCEL, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    ToastUtilsKing.middleShowShort(mContext,"取消成功");
                    getData();
                } else {
                    mView.onOrderCancle(cancelReason);
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                Log.i(TAG,"getOrderCancle ==> AuzFailure");
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //联系客服
    public void inittell() {
        Params params = new Params();
        mAuz.auzget(UrlPool.SYSTEM_LIST, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    List<SystemBean> msystemBean = JSON.parseArray(data, SystemBean.class);
                    for (int i = 0; i < msystemBean.size(); i++) {
                        if ("kjb_ke_tell".equals(msystemBean.get(i).getKeyName())) {
                            mCustomer = msystemBean.get(i).getKeyValue();
                            break;
                        }
                    }
                    if (!TextUtils.isEmpty(mCustomer)) {
                        Intent mTelintent = new Intent(Intent.ACTION_DIAL);
                        Uri Urldata = Uri.parse("tel:" + mCustomer.replace("\\", ""));
                        mTelintent.setData(Urldata);
                        mContext.startActivity(mTelintent);
                    }
                } else {
                    mView.oninittell();
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //订单状态显示
    public void OrderStart() {
        if (ListUtils.isEmpty(mOrderDetails.getOptRecords()) || mOrderDetails.getOptRecords().size() == 0) {
            return;
        }
        PopOrderStartModule module = new PopOrderStartModule(mContext, mOrderDetails.getOptRecords());
        Popwindows window = PopWindowUtil.getPopupWindow(module.getView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
                .LayoutParams.MATCH_PARENT);
        module.setPopwindow(window);
        window.show(mView.getRelImgDian(), Popwindows.Location.TOP);

    }

    //评价布局
    public void getEvaluate() {
        PopEvaluateModule mEvaluate = new PopEvaluateModule(mContext, new PopEvaluateModule.PopEvaluateListener() {
            @Override
            public void getEvaluate(int grade, String title) {
                EvaluateData(grade, title);
            }
        });
        Popwindows window = PopWindowUtil.getPopupWindow(mEvaluate.getView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
                .LayoutParams.MATCH_PARENT);
        mEvaluate.setPopwindow(window);
        window.show(mView.getRelImgDian(), Popwindows.Location.TOP);
    }

    //评价接口
    public void EvaluateData(final int grade, final String title) {
        Params params = new Params();
        params.add("grade", grade);
        params.add("orderCode", mView.getOrderCode());
        params.add("title", title);
        mAuz.auzpost(UrlPool.POST_ORDER_COMMENT, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    getData();
                    Toast toast = Toast.makeText(mContext, "评价成功", Toast.LENGTH_SHORT);
                    ToastUtils.showMyToast(toast, 3000);
                } else {
                    mView.onEvaluateData(grade, title);
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //支付布局  先请求这个接口GET_COUPONS_PRICE获取优惠数据
    public void getPayOrder() {
        mPopPayOrder = new PopPayOrderModule(mContext, mOrderDetails.getOrderInfo().getTotalAmount(),
                mOrderDetails.getOrderInfo().getDeposit(), Double.valueOf(mOrderDetails.getOrderInfo().getTailMoney())
                , mCouponsdiscount, mOrderDetails.getOrderInfo().getServiceCode(), mTotalAmount,mStart
                ,mOrderDetails.getOrderInfo().getVersion(),Double.valueOf(mOrderDetails.getAssemble().getAssemblePrice()),mOrderDetails.getDiscounts(), new PopPayOrderModule.PopPayListener() {
            @Override
            public void getPayOrder(String PayType, String PayPrice) {
                if (StateUtils.PAY_ZERO.equals(PayType)) { //尾款为0调用接口支付
                    if (mOrderDetails.getOrderInfo().getDeposit().equals(mView.getIncomeText().getText().toString())) {
                        ByNoMoney();
                    } else {
                        ByCoupon();
                    }
                } else { //第三方支付
                    onPaySurplus(PayType);
                }
            }
        });
        Popwindows window = PopWindowUtil.getPopupWindow(mPopPayOrder.getView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
                .LayoutParams.MATCH_PARENT);
        mPopPayOrder.setPopwindow(window);
        window.show(mView.getRelImgDian(), Popwindows.Location.TOP);
    }

    //选择优惠卷返回数据
    public void CarRollData(CardRollBean mRollBean) {
        mCouponCustomerCode = mRollBean.getCouponCustomerCode();
        mCouponsdiscount = (double) mRollBean.getCoupon().getDiscount();
        getpayTail();
        getPayOrder();
    }

    //获取优惠卷数据
    public void getCoupons() {
        Params params = new Params();
        params.add("price", mOrderDetails.getOrderInfo().getTotalAmount());
        params.add("serviceCode", mOrderDetails.getOrderInfo().getServiceCode());
        mAuz.auzget(UrlPool.GET_COUPONS_PRICE, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    if (!TextUtils.isEmpty(data)) {
                        CardRollBean mBean = JSON.parseObject(data, CardRollBean.class);
                        mCouponCustomerCode = mBean.getCouponCustomerCode();
                        mCouponsdiscount = (double) mBean.getCoupon().getDiscount();
                    } else {
                        mCouponsdiscount = 0.00;
                        mCouponCustomerCode = "";
                    }
                    getpayTail();
                } else {
                    mView.onCoupons();

                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                Log.i(TAG,"getCoupons ==> AuzFailure");
                mView.onFailure(errorCode, msg);
            }
        });
    }

    public void getpayTail() {
        if (Double.valueOf(mOrderDetails.getOrderInfo().getTailMoney()) != 0.00) {
            DecimalFormat format = new DecimalFormat("#0.00");
            if (mCouponsdiscount != 0.00) {
                if (Double.valueOf(mOrderDetails.getOrderInfo().getTailMoney()) - mCouponsdiscount > 0) {
                    BigDecimal b = new BigDecimal((Double.valueOf(mOrderDetails.getOrderInfo().getTailMoney()) - mCouponsdiscount));//金额进行精确计算
                    double DifferencePrice = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    mView.getTailMoney().setText("\u00A5" + format.format(DifferencePrice));
                } else {
                    mView.getTailMoney().setText("\u00A5 0.00");
                }
            } else {
                //判断是否有折扣，计算折扣优惠和立减优惠
                for (int i = 0; i < mOrderDetails.getDiscounts().size(); i++) {
                    if (mOrderDetails.getDiscounts().get(i).getDescribeType().equals("PERCENTAGE")) {//折扣优惠
                        discount = Double.valueOf(mOrderDetails.getOrderInfo().getTotalAmount()) * (10 - mOrderDetails.getDiscounts().get(i).getPrice()) / 10;
                    } else if (mOrderDetails.getDiscounts().get(i).getDescribeType().equals("AMOUNT")) {//立减优惠
                        minus = mOrderDetails.getDiscounts().get(i).getPrice();
                    }
                }
                Log.i(TAG,"getpayTail ==> discount = "+discount+" minus = "+minus+" mTotalAmount = "+mTotalAmount);
                BigDecimal b = new BigDecimal(Double.valueOf(mOrderDetails.getOrderInfo().getTailMoney()) - discount - minus);//金额进行精确计算
                double DifferencePrice = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                mView.getTailMoney().setText("\u00A5" + format.format(DifferencePrice));
            }
        } else {
            mView.getTailMoney().setText("\u00A5 0.00");
        }

    }

    //尾款为0支付
    public void ByNoMoney() {
        Params params = new Params();
        //params.add("couponCustomerCode","");
        params.add("orderCode", mView.getOrderCode());
        mAuz.auzpost(UrlPool.POST_PAY_BY_NO_MONEY, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    mView.onByNoMoney();
                } else {
                    mView.NoMoney();
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //尾款为0支付-优惠卷抵扣全额
    public void ByCoupon() {
        Params params = new Params();
        params.add("couponCustomerCode", mCouponCustomerCode);
        params.add("orderCode", mView.getOrderCode());
        mAuz.auzpost(UrlPool.POST_PAY_BY_COUPON, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
               /* Toast toast = Toast.makeText(mContext, "支付成功", Toast.LENGTH_SHORT);
                ToastUtils.showMyToast(toast, 3000);
                getData();*/
                if (code == 0) {
                    mView.onByNoMoney();
                } else {
                    mView.onByCoupon();
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //第三方支付
    public void onPaySurplus(final String PayType) {
        Params params = new Params();
        params.add("couponCustomerCode", mCouponCustomerCode);//用户优惠卷编码
        params.add("orderCode", mView.getOrderCode());//订单code编码
        params.add("payChannelEnum", PayType);//支付渠道枚举，支付渠道枚举为支付的必填项；0：支付宝支付 1：微信支付；目前只支持【支付宝支付,微信支付】两种
        params.add("tradeType", "2");//交易类型枚举，交易类型枚举为支付的需要必填；0： JSAPI 2：APP ，目前只支持【JSAPI,APP】两种
        mAuz.auzpost(UrlPool.POST_PAY_SURPLUS, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    PayParamsBean mParams = JSON.parseObject(data, PayParamsBean.class);
                    if (mParams.isNoPayment()) {
                        EventBus.getDefault().post(new PayResult(true, mParams.getOutTradNo()), "e-PayResult");
                    } else {
                        if (StateUtils.PAY_ALI.equals(mParams.getPayChannelEnum())) { //支付宝
                            PayUtil.getInstance().aliPay(mContext, mParams);
                        } else if (StateUtils.PAY_WX.equals(mParams.getPayChannelEnum())) { //微信
                            mView.getWXPayCode(mParams.getOutTradNo());
                            PayUtil.getInstance().WXPay(mContext, mParams.getWxPayResult());
                        }
                    }
                } else {
                    mView.OnonPaySurplus(PayType);
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    public void getRewardData(){
        mAuz.auzpost(UrlPool.POST_REWARD_LIST, new Params(), new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                List<RewardBean> mListBean = JSON.parseArray(data, RewardBean.class);
                if (!ListUtils.isEmpty(mListBean)){
                    onReward(mListBean);
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //打赏布局
    public void onReward(List<RewardBean> mListBean){
        PopRewardModule mRewardModule=new PopRewardModule(mContext, mListBean, new PopRewardModule.PopRewardListener() {
            @Override
            public void getPayOrder(String Price, String rewardCode) {
                getRewardPayOrder(Price,rewardCode);
            }
        });
        Popwindows window = PopWindowUtil.getPopupWindow(mRewardModule.getView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
                .LayoutParams.MATCH_PARENT);
        mRewardModule.setPopwindow(window);
        window.show(mView.getRelImgDian(), Popwindows.Location.TOP);
    }

    //支付布局
    public void getRewardPayOrder(final String Price, final String rewardCode) {
        PopPayDepositModule mPopPayOrder = new PopPayDepositModule(mContext, Double.valueOf(Price), "支付金额", new PopPayDepositModule.PopPayListener() {
            @Override
            public void getPayOrder(String PayType, String PayPrice) {
                onPayReward(rewardCode,Price,PayType);
            }

        });
        Popwindows window = PopWindowUtil.getPopupWindow(mPopPayOrder.getView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
                .LayoutParams.MATCH_PARENT);
        mPopPayOrder.setPopwindow(window);
        window.show(mView.getRelImgDian(), Popwindows.Location.TOP);
    }

    //POST_REWARD_PAY
    public void onPayReward(final String rewardCode,final String PayPrice,final String PayType){
        Params params = new Params();
        params.add("orderCode",mView.getOrderCode());//订单code编码
        params.add("payChannelEnum",PayType);//支付渠道枚举，支付渠道枚举为支付的必填项；0：支付宝支付 1；2: 账户余额 目前只支持 【支付宝支付,微信支付,账户余额】三种
        params.add("rewardCode",rewardCode);//打赏项编码
        params.add("rewardMoney",PayPrice);//打赏金额
        params.add("tradeType","2");//交易类型枚举，交易类型枚举为支付的需要必填；0： JSAPI 2：APP ，目前只支持【JSAPI,APP】两种
        mAuz.auzpost(UrlPool.POST_REWARD_PAY, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    PayParamsBean mParams = JSON.parseObject(data, PayParamsBean.class);
                    if (mParams.isNoPayment()) {
                        EventBus.getDefault().post(new PayResult(true, mParams.getOutTradNo()), "e-PayResult");
                    } else {
                        if (StateUtils.PAY_ALI.equals(mParams.getPayChannelEnum())) { //支付宝
                            PayUtil.getInstance().aliPay(mContext, mParams);
                        } else if (StateUtils.PAY_WX.equals(mParams.getPayChannelEnum())) { //微信
                            mView.getWXPayCode(mParams.getOutTradNo());
                            PayUtil.getInstance().WXPay(mContext, mParams.getWxPayResult());
                        }
                    }
                } else {
                    mView.OnPayReward(rewardCode,PayType,PayPrice);
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }

    //修改服务时间选择
    public void TimeChoice() {
        PopTimeChoiceModule mPopModule = new PopTimeChoiceModule(mContext, mStartsTime, mTimeInterval, mEndTime, new PopTimeChoiceModule.PopTiemListener() {
            @Override
            public void Determine(String OrderTime) {
                //mView.getServiceTimes().setText(OrderTime);
                Log.i(TAG,"TimeChoice ==> OrderTime = "+OrderTime);
                if (mLoadDialog == null){
                    mLoadDialog = new LoadDialog(mContext, "");
                }
                mLoadDialog.show();
                modifyOrderInfo(OrderTime);
            }
        });
        window = PopWindowUtil.getPopupWindow(mPopModule.getView(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
                .LayoutParams.MATCH_PARENT);
        mPopModule.setPopwindow(window);
        window.show(mView.getServiceTimes(), Popwindows.Location.TOP);
    }

    /**
     *修改订单服务时间
     * @param serviceTime
     */
    public void modifyOrderInfo(String serviceTime){

        Params params = new Params();
        params.add("orderCode",mView.getOrderCode());//订单code编码
        params.add("serviceTime",serviceTime);
        mAuz.auzpost(UrlPool.POST_MODIFYORDERINFO, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    Toast.makeText(mContext, "修改订单服务时间成功", Toast.LENGTH_SHORT);
                    getData();
                    mLoadDialog.dismiss();
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mLoadDialog.dismiss();
                //Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
                mView.onFailure(errorCode, msg);
            }
        });
    }

    /**
     * 距离服务1小时还没有人接单，提醒客户
     */
    public void reminderDialog(){
        dialogshoweminder=new KAlertDialog(mContext,"很抱歉暂时没有找到合适的保洁员，请您选择：");
        dialogshoweminder.setRightTxt("取消订单", new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {

                dialogshoweminder.dismiss();
                cancelReasonDialog();
            }
        });
        dialogshoweminder.setLeftTxt("继续等待", new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                dialogshoweminder.dismiss();
            }
        });
        dialogshoweminder.show();
    }
    /**
     * 收藏保洁员
     */
    public void collectionCleaner(){
        if (mLoadDialog == null){
            mLoadDialog = new LoadDialog(mContext, "");
        }
        mLoadDialog.show();
        Params params = new Params();
        params.add("cleanerCode",mOrderDetails.getCleanerInfo().getCleanerCode());//保洁员Code
        params.add("title","");
        mAuz.auzpost(UrlPool.POST_COLLECTION_CLEANER, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    TextDrawable.drawable(mContext, mView.getCollection(), R.drawable.collection_selector, 1);
                    mLoadDialog.dismiss();
                    mView.onSuccess(code, "收藏保洁员成功");
                    mOrderDetails.getCleanerInfo().setCollected(true);
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mLoadDialog.dismiss();
                //Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
                mView.onFailure(errorCode, msg);
            }
        });
    }

    /**
     * 取消收藏保洁员
     */
    public void CancelCollectionCleaner(){
        if (mLoadDialog == null){
            mLoadDialog = new LoadDialog(mContext, "");
        }
        mLoadDialog.show();
        Params params = new Params();
        params.add("cleanerCode",mOrderDetails.getCleanerInfo().getCleanerCode());//保洁员Code
        params.add("title","");
        mAuz.auzpost(UrlPool.POST_UNCOLLECTION_CLEANER, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                if (code == 0) {
                    TextDrawable.drawable(mContext, mView.getCollection(), R.drawable.uncollection_selector, 1);
                    mLoadDialog.dismiss();
                    mView.onSuccess(code, "取消收藏成功");
                    mOrderDetails.getCleanerInfo().setCollected(false);
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mLoadDialog.dismiss();
                //Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
                mView.onFailure(errorCode, msg);
            }
        });
    }

    /**
     * 取消订单原因
     */
    private void cancelReasonDialog(){
        final CancelReasonDialog dialogshow=new CancelReasonDialog(mContext,"");
        dialogshow.setRightTxt("确定取消", new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                Log.i(TAG,"Cancel() ==> cancelReason = "+dialogshow.cancelReason);
                if("".equals(dialogshow.cancelReason)){
                            /*Toast toast = Toast.makeText(mContext, "请选择取消原因", Toast.LENGTH_SHORT);
                            ToastUtils.showMyToast(toast, 3000);*/
                    ToastUtilsKing.middleShowShort(mContext,"请选择或输入取消原因");
                    return;
                }
                getOrderCancle(dialogshow.cancelReason);
                dialogshow.dismiss();
            }
        });
        dialogshow.setWaitLong(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {

                dialogshow.waitLongChecked();
            }
        });
        dialogshow.setTimeWrong(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                dialogshow.timeWrongChecked();
            }
        });
        dialogshow.setOther(new View.OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                dialogshow.otherChecked(hasFocus);
                if(hasFocus){
                    dialogshow.addTextChanged();
                }
            }
        });
        dialogshow.setCancelable(false);

        dialogshow.show();
    }

}
